using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using FireStarterModeller.BO;
using Habanero.Base;

namespace FireStarter.CodeGeneration
{
    public class LogicProjectGenerator : ProjectGenerator
    {
        public override Result Generate()
        {
            CheckRequiredPropertiesSet();
            if (ModelSolution.BOProjectName == null) throw new ReferenceMissingException("BOProjectName");
            Directory.CreateDirectory(ProjectPath);

            LogicProjectTemplateLoader logicProjectTemplateLoader = new LogicProjectTemplateLoader();

            string contents = logicProjectTemplateLoader.GetAssemblyInfo(ProjectName);
            string assemblyInfoFileName = Utilities.CreateFile(ProjectPath, "Properties\\AssemblyInfo.cs", contents);

            string projectFileName = Path.Combine(ProjectPath, ProjectName + ".csproj");
            ProjectFileManager projectFileManager = new ProjectFileManager(projectFileName, OutputType.Library, SolutionGenerator.CodeTemplate);
            projectFileManager.AddProjectReference(ModelSolution.BOProjectName, SolutionGenerator.SolutionDirectory);
            projectFileManager.AddReference(Path.Combine(SolutionGenerator.HabaneroReferencePath, "Habanero.Base.dll"));
            projectFileManager.AddReference(Path.Combine(SolutionGenerator.HabaneroReferencePath, "Habanero.BO.dll"));
            projectFileManager.SaveProjectFile();
            return new Result(true);
        }
    }
}
